package com.kedll.library.addimg;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;

import com.kedll.library.R;
import com.kedll.library.databinding.FragmentViewImg01Binding;
import com.kedll.library.fragment.KBaseFragment;
import com.kedll.library.listener.OnSetTitleBarVisibleListener;
import com.kedll.library.listener.SimpleImageLoadingListener;
import com.kedll.library.mvp.BasePresenter;
import com.kedll.library.util.ImageLoadUtil;
import com.kedll.library.util.ViewUtil;


/**
 * @author QiQi
 */
public class ViewImgFragment01 extends KBaseFragment<FragmentViewImg01Binding, BasePresenter> implements View.OnClickListener {

    /**
     * 图片地址
     */
    private String uri;
    private OnSetTitleBarVisibleListener titleBarVisibleListener;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnSetTitleBarVisibleListener) {
            titleBarVisibleListener = (OnSetTitleBarVisibleListener) context;
        }
    }

    @Override
    public void onClick(View v) {
        if (titleBarVisibleListener != null) {
            titleBarVisibleListener.setTitleBottomVisibly();
        }
    }


    @Override
    protected void init() {
        Bundle bd = getArguments();
        uri = bd.getString("imgURI");
    }

    @Override
    protected void initEvent(Bundle savedInstanceState) {
        ImageLoadUtil.getInstance()
                .setImageLoadingListener(new SimpleImageLoadingListener() {
                    @Override
                    public void onLoadingFailed(String imageUri, View view) {
                        super.onLoadingFailed(imageUri, view);
                        ViewUtil.setGone(mBinding.processLayoutRoot.rlProgressbar, true);
                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Drawable loadedImage) {
                        super.onLoadingComplete(imageUri, view, loadedImage);
                        ViewUtil.setGone(mBinding.processLayoutRoot.rlProgressbar, true);
                    }
                })
                .ImageLoad(this, uri, mBinding.pvViewImg);

        mBinding.pvViewImg.setOnClickListener(this);
        mBinding.processLayoutRoot.rlProgressbar.setBackgroundColor(0x00000000);
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_view_img01;
    }

}
